#! /usr/bin/env bash
trim_left(){
  sub=${2}
  echo ${1#${sub}}
}

trim_right(){
  echo ${1%$2}
}

str_eq(){
  [[ "$1" == "$2" ]]
}

str_replace(){
    echo ${1//${2}/${3}}
}

str_pos(){
    if [[ ${#1} -lt ${#2} ]]; then
        echo -1
        return
    fi
    rest=${1#*${2}}
    if [[ $1 == $rest ]]; then
        echo -1
        return
    fi
    echo $(( ${#1} - ${#rest} - ${#2}))
}

has_pre(){
   str_eq ${1:0:${#2}} $2
}

has_sub(){
   pos=$((${#1}-${#2}))
   str_eq ${1:${pos}} $2
}

# if str_eq "a" "a" ;then
#   echo "---"
# fi

# if has_pre "http://www.a.com" "http"; then 
#   echo "has pre http"
# fi

#str_pos "xxaaaa"  "a"
